package com.binarytree;

public class Solution32 {
    public TreeNode sortedArrayToBST(int[] nums) {
        return sortedArrayToBST(nums,0, nums.length);
    }

    public TreeNode sortedArrayToBST(int[] nums,int low, int high) {
        if (low >= high) return null;
        if ((high-low) == 1) return new TreeNode(nums[low]);
        int mid = (low+high) /2;
        TreeNode root = new TreeNode(nums[mid]);
        root.left = sortedArrayToBST(nums,low,mid);
        root.right = sortedArrayToBST(nums,mid+1,high);
        return root;
    }

}
